package com.atguigu.mvc.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class WebUtil {

    /**
     * 获取 HttpServletRequest
     *
     * @return
     */
    public static HttpServletRequest getServletRequest() {
        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
        return request;
    }

    /**
     * 判断是否异步请求
     *
     * @return boolean
     */
    public static boolean isAsyncRequest() {
        return "XMLHttpRequest".equalsIgnoreCase(getServletRequest().getHeader("x-requested-with"));
    }

}
